home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / PCTERM.ASM < prev    next >
Assembly Source File  |  1990-02-11  |  18KB  |  571 lines

  1. ;--------------------------------------------------------------------
  2. ;                             DUMBTERM
  3. ;  Original author is CJ Dunford 09/12/83, modified by Jeff Firestone
  4. ;  on 01/15/84.  This program sets up the interrupt for COM1.  It uses
  5. ;  buffered communications.  The program is based upon PC Tech Journal
  6. ;  Jan '84, p144-186.
  7. ;---------------------------------------------------------------------
  8.  
  9. bufsize      equ     4096            ;4K Buffer
  10.  
  11. LF           equ     0Ah
  12. CR           equ     0Dh
  13. K_ESC          equ     1Bh
  14.  
  15. ; ------- BIOS calls
  16.  
  17. RS232        equ     14h            ;RS232 service
  18. kbd_io       equ     16h            ;Keyboard service
  19.  
  20. ; ------- INS8250 registers
  21.  
  22. THR          equ     3F8h           ;Trans holding register (write)
  23. RBR          equ     3F8h           ;Recieve buffer register (read)
  24. IER          equ     3F9h           ;Interrupt inable register
  25. LCR          equ     3FBh           ;Line control register
  26.                                     ;  Bit 7 of LCR is "DLAB". DLAB must
  27.                                     ;  be zero to access THR, RBR, IER.
  28. MCR         equ      3FCh           ;Modem control register
  29. LSR         equ      3FDh           ;Line status register
  30. MSR         equ      3FEh           ;Modem status register
  31.  
  32. ; ------- Comm parameter definition
  33. ; Refer to IBM Tech Ref manual page A-20
  34. ; See PROC INIT for usage.
  35. ; ---------------------------------------
  36. commparm   record baud:3, parity:2, stopbits:1, wordbits:2
  37.  
  38. ; Buad rates
  39. B110        equ      000b
  40. B150        equ      001b
  41. B300        equ      010b
  42. B600        equ      011b
  43. B1200       equ      100b
  44. B2400       equ      101b
  45. B4800       equ      110b
  46. B9600       equ      111b
  47.  
  48. ; Parity
  49. no_parity    equ     00b
  50. odd_parity   equ     01b
  51. even_parity  equ     11b
  52.  
  53. ; Stop bits
  54. stop1        equ     0
  55. stop2        equ     1
  56.  
  57. ; Data bits
  58. data7        equ     10b
  59. data8        equ     11b
  60.  
  61.  
  62. ;*****************************
  63. ;         MACROS
  64. ;*****************************
  65.  
  66. @bioscall MACRO call_num, parm
  67. ;; Generates an 'INT call_num', with parm in AH
  68.             IFNB     <parm>
  69.               mov    ah,parm
  70.             ENDIF
  71.             int      call_num
  72.             ENDM
  73.  
  74.  
  75. @doscall MACRO function, parm
  76. ;; Generates a DOS function call with parm in AH
  77.             IFNB     <parm>
  78.               mov    al,parm
  79.             ENDIF
  80.             @bioscall 21h,function
  81.             ENDM
  82.  
  83.  
  84. ;******************************
  85. ;    DATA & STACK SEGMENTS
  86. ;******************************
  87.  
  88. data segment para public 'data'
  89.  
  90. ; ----- The string section
  91. sgreeting      db      '--- ONLINE -0--',cr,lf,'$'
  92. sgoodbye       db      cr,lf,'--- OFFLINE ---',cr,lf,'$'
  93. serr1          db      '<R>$'          ;RS232 receive error
  94. serr2          db      '<S>$'          ;RS232 send error
  95. serr3          db      '<B>$'          ;Receive buffer overflow error
  96.  
  97. ; ----- Flags
  98. brcv_err       db     0                ;Nonzero on RS232 receive error
  99. boverflow      db     0                ;Nonzero on buffer overflow
  100. bdoneflag      db     0                ;Nonzero after ESC from kbd
  101.  
  102. ; ----- Receive data buffer and associated pointers
  103. ; >> Buffer is empty if head point4er = tail pointer
  104. wbufhead       dw     buffer           ;Pointer to head of buffer
  105. wbuftail       dw     buffer           ;Pointer to tail of buffer
  106. buffer         db     BUFSIZE dup (?)
  107. bufend         equ    $
  108. data ends
  109.  
  110. ; ----- Stack
  111. stack segment para stack 'stack'
  112.               db      256 dup (?)
  113. stack ends
  114.  
  115.  
  116. ;* * * * * * * * * * * * * * * * *
  117. ;         PROGRAM BODY
  118. ;* * * * * * * * * * * * * * * * *
  119.  
  120. code segment para public 'code'
  121.              assume cs:code, ds:data, ss:stack
  122.  
  123. main         proc     far
  124.  
  125. ; ------ Initialize
  126.              push     ds                ;Set up long return to DOS
  127.              sub      ax,ax
  128.              push     ax
  129.              call     init              ;Rest of initialization
  130.  
  131. ; ------ Main program loop
  132. M100:        call     buffer_check      ;Check RS232 buffer, display if char
  133.              call     kb_check          ;Check kbd, Send to RS232.
  134.              test     bdoneflag,0FFh    ;Non-zero if done
  135.              jz       M100              ;Loop till ESC received
  136.  
  137. ; ------ ESC received.  Clean up interrupt & exit
  138.              call     cleanup
  139.              ret                        ;Return to DOS
  140. main         endp
  141.  
  142. ;* * * * * * * * * * * * * * * * * * * *
  143. ;         PRIMARY BLOCKS
  144. ;* * * * * * * * * * * * * * * * * * * *
  145.  
  146. ; ------ Init ---------------------------------
  147. ;Program initialization
  148. ;  set up RS232
  149. ;  set up vector for RS232 interrupt (INT 0Ch)
  150. ;  Enable IRQ4
  151. ;  Enable RS232 interrupt on data ready
  152. ; --------------------------------------------
  153.  
  154. init         proc     near
  155.  
  156. ; ----- Initialize RS232 300,8,N,1
  157.              mov      dx,0
  158.              mov      al,commparm <B9600,even_Parity,stop1,data7>
  159.              @bioscall RS232,0
  160.  
  161. ; ----- Set up INT '0C' for IRQ4
  162.             cli                               ;Interrupts off during setup
  163.             push      ds                      ;Save DS
  164.             mov       dx,offset ISR           ;Point to RS232 ISR in DS:DX
  165.             push      cs
  166.             pop       ds
  167.             @doscall 25h,0Ch                  ;Set vector intr for IRQ4
  168.             pop       ds                      ;Restore DS
  169.  
  170. ; ------ Enable IRQ4 on 8259 interrupt controller
  171.             in        al,21h                  ;Get current mask
  172.             and       al,11101111b            ;Reset IRQ4 mask
  173.             out       21h,al                  ;restore to IMR
  174.  
  175. ; ------ Enable 8250 data ready interrupt
  176.             mov      dx,LCR                   ;DX <== LCR
  177.             in       al,dx                    ;reset DLAB for IER access
  178.             and      al,01111111b
  179.             out      dx,al
  180.             mov      dx,IER                   ;address IER
  181.             mov      al,00000001b             ;Enable data-ready interrupt
  182.             out      dx,al
  183.  
  184. ; ------ Enable OUT2 on 8250
  185.             mov      dx,MCR                   ;Address MCR
  186.             mov      al,00001000b             ;Enable OUT2
  187.             out      dx,al
  188.             sti
  189.  
  190. ; ------ Display greeting & return
  191.             mov      ax,data                  ;Establish data seg address
  192.             mov      ds,ax
  193.             mov      dx,offset sgreeting      ;Point to greeting
  194.             call     strdisp                  ;Display it
  195.             ret
  196. init endp
  197.  
  198. ; ------ Buffer Check ------------------
  199. ; RS232 buffer check
  200. ;
  201. ; This block checks the received data buffer.
  202. ; It functions as follows:
  203. ;
  204. ; If the RS232 input buffer is not empty
  205. ;   Get the first character
  206. ;   Display the character
  207. ;   Update buffer pointer
  208. ; If the RS232 receive error flag is nonzero
  209. ;   Display an error indicator
  210. ;
  211. ; Entry:
  212. ;   No requirement
  213. ; Exit
  214. ;   AX, BX, DX destroyed
  215. ; --------------------------------------
  216.  
  217.  
  218. buffer_check proc near
  219.  
  220. ; ------ Check buffer status
  221.           mov      bx,wbufhead               ;buffer head pointer
  222.           cmp      bx,wbuftail               ;buffer empty if head = tail
  223.           je       BC100
  224.  
  225. ; ------ Something in buffer--get 1st char, fix pointers
  226.           mov      al,[bx]                   ;get the char
  227.           call     incptr                    ;Bump buffer head pointer
  228.           mov      wbufhead,bx
  229.  
  230. ; ------ Display character received. Filter CR/LF
  231.           cmp    al,LF                       ;Is it a line feed
  232.           je     BC100                       ;Skip display if yes
  233.           call   chdisp                      ;Display if no
  234.           cmp    al,CR
  235.           jne    BC100
  236.           mov    al,LF
  237.           call   chdisp
  238.  
  239. ; ------ Test RS232 receive status; display errors
  240. BC100:    Test   brcv_err,0FFh               ;Flag nonzero if errors
  241.           jz     BC200                       ;Jump if no errors
  242.           mov    dx,offset serr1             ;Point to error msg
  243.           call   strdisp
  244.           mov    brcv_err,0                  ;Clear error flag